package com.zhengke.controller;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.mysql.fabric.xmlrpc.base.Array;
import com.zhengke.common.object.Result;
import com.zhengke.pojo.MallSupplier;
import com.zhengke.service.MallSupplierService;
@Controller
//@RequestMapping("")
public class MallSupplierController {
	 /**
     * ssx
     * */
	@Autowired
	private MallSupplierService service;
	
	
	@RequestMapping("CGGL010!query.do")//用作跳转，到供应商信息页面
	public String query(){
		return "supplier/list";
	}
	/**
	 * 信息查询
	 * */
	@RequestMapping("supplier/list.do")
    @ResponseBody
	public Result list(String supplierName, String contactsPhone, String supplierStatus,int page,int limit){
    	Result rs = null;    	
    	try {
			 rs = service.querySuppliers(supplierName, contactsPhone, supplierStatus, page, limit);
			return rs;
		} catch (Exception e) {
			e.printStackTrace();
		}  	
		return new Result();
	}
	
	
	/**
	 * 
	 * 删除行
	 * */
	@RequestMapping("supplier/delete.do")
    @ResponseBody
	public Result delete(Integer supplierId){
    	Result rs = null;    	
    	try {
			 rs = service.deleteSuppliers(supplierId);
			return rs;
		} catch (Exception e) {
			e.printStackTrace();
		}  	
		return null;
	}
	
	
	/**
	 * 
	 * 修改状态
	 * */
	@RequestMapping("supplier/update.do")
    @ResponseBody
	public Result update(String supplierStatus,Integer supplierId){
    	Result rs = null;    	
    	try {
    		//System.out.println(supplierId+"---------------"+supplierStatus);
    		if(supplierStatus.equals("0")) {
    			supplierStatus="1";
    		}else{
    			supplierStatus="0";
    		}
    		//System.out.println(supplierId+"---------------"+supplierStatus);
			 rs = service.updateSuppliers(supplierStatus,supplierId);
			return rs;
		} catch (Exception e) {
			e.printStackTrace();
		}  	
		return null;
	}
	
	
	
	@RequestMapping("supplier/updates.do")//用作跳转，到修改信息页面
	public String add(){
		return "supplier/toGcUpd2";
	}
	
	
	/**
	 * 修改信息
	 * */
	@RequestMapping("supplier/updatess.do")
    @ResponseBody
	public Result uptatesSuppliers(MallSupplier mallSupplier){
    	Result rs = null;
    	try {
			rs = service.updatesSuppliers(mallSupplier);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	return null;
	}
	
	
	@RequestMapping("supplier/adds.do")//用作跳转，到新增页面
    public String adds(){
	   return "supplier/add";
	}
	
	/**
	 * 新增
	 * */
	@RequestMapping("supplier/add.do")
    @ResponseBody
	public Result addsSuppliers(MallSupplier mallSupplier){
    	Result rs = null;
    	mallSupplier.setCreateTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
    	try {
			service.addsSuppliers(mallSupplier);
		} catch (Exception e) {
			e.printStackTrace();
		}
    	return null;
	}
	
	
	
	/**
	 * 批量删除
	 * */
	@RequestMapping("supplier/deletes.do")
    @ResponseBody
	public Result deletesSuppliers(String data){
    	Result rs = null;
    	System.out.println(data+"=======================");
    	try {
    		List<Integer> List = new ArrayList<Integer>();
    		List<MallSupplier> supList = JSONObject.parseArray(data ,MallSupplier.class);
    		for (MallSupplier mallSupplier : supList) {
    			List.add(mallSupplier.getSupplierId());
			}
    	      
    		rs = service.deletesSuppliers(List);
    		
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	return null;
	}
	
	
	
}
